import React from "react";
import axios from "axios";
import { useEffect, useState } from "react";
import { SidebarStaff } from "../../components/Sidebar";
import { Supervision } from "../../components/Supervision";

export const StaffModule: React.FC = () => {
  const [saRoleCheck, setSaRoleCheck] = useState(false);

  //check if staff is already logged in
  useEffect(() => {
    axios({
      method: "GET",
      headers: { satoken: window.localStorage.getItem("satoken") },
      url: "http://localhost:8080/user/staff/module",
    }).then((res) => {
      if (res.data.success) {
        setSaRoleCheck(true);
      } else {
        setSaRoleCheck(false);
      }
    });
  }, []); // initial render

  if (saRoleCheck) {
    return (
      <>
        <SidebarStaff />
        <Supervision />
      </>
    );
  } else {
    return <></>;
  }
};
